<template>
  <div class="outer9">
    <div class="inter1">
      <h1>订单</h1>
    </div>
    <ul class="inter1 hh">
      <li class="bb" :class="{checked:index==flag}" v-for="(btn,index) in btns" :key="index" @click="changeList(index)">
        {{btn.value}}
      </li>
    </ul>
    <div class="inter2">
      <div class="inter21">
        <input type="checkbox" class="checkAll"><span class="s1">订单</span>
        <span class="s2">商品名称</span>
        <span class="s2" style="margin-left: 80px;">状态</span>
        <span class="s2">单价</span>
        <span class="count">数量</span><span class="total">小计</span><span class="del">操作</span>
      </div>
      <div class="inter22">
        <ul>
          <li v-for="(item, index) in orderList" :key="index">
            <input type="checkbox" class="check" :checked="item.check"><img :src="item.image" alt="">
            <span class="s1">{{item.productName}}
            <span class="s1" style="margin-left: 20px;">{{item.orderStateDes}}</span></span><span class="money">¥</span>
            <span class="price">{{item.price}}</span><input type="button" value=" " class="sub">
            <span class="count">{{item.productNum}}</span><input type="button" value=" " class="add">
            <span class="money1">¥</span><span class="total">{{item.productNum * item.price}}</span>
            <span class="del">
              <span @click="payOrder(index)">支付</span>
              <span> | </span>
              <span @click="takeDelivery(index)">收货</span>
              <span> | </span>
              <span @click="afterSell(index)">申请退款</span>
            </span>
          </li>
        </ul>
      </div>
      <div class="inter23">
        <div class="picture">
          <img src="../assets/img/购物车.png" alt="">
        </div>
        <p>没有相关订单信息！</p>
        <a href=""><span>去逛逛</span></a>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        btns:[
          {
            key: 1,
            value:'全部'
          },
          {
            key: 2,
            value:'待支付'
          },
          {
            key: 3,
            value:'待发货'
          },
          {
            key: 4,
            value:'待收货'
          },
          {
            key: 5,
            value:'已收货'
          },
          {
            key: 6,
            value:'售后'
          }
        ],
        flag: 1,
        orderList: []
      }
    },
    mounted() {
      if (this.$cookies.get('user') === null){
        this.$router.push({path: '/login'})
      }
      this.getOrderList()
    },
    watch: {
      flag: function () {
        this.getOrderList()
      }
    },
    methods:{
      changeList(index){
        debugger
        this.flag = index
      },
      getOrderList: function () {
        this.$axios({
          method: 'post',
          url: 'http://localhost:8080/api/order/queryorder',
          data: {
            queryFlag: this.btns[this.flag].key,
            userId: this.$cookies.get('user').userId
          },
          headers:{
            'Content-Type': 'application/json'
          }
        }).then(res => {
          let data = res.data
          this.orderList = []
          if (data.resultCode === '0'){
            let list = data.orderAndDetailList
            for (let i = 0; i < list.length; i++){
              for (let j= 0; j < list[i].orderDetailList.length; j++){
                let item = JSON.parse( JSON.stringify(list[i].orderDetailList[j]))
                item.image = require('../assets/img/s'+(i+1).toString()+'.png')
                item.productName = '简约时尚水泥花瓶'
                item.orderStateDes = this.stateDes(item.orderState)
                this.orderList.push(item)
              }
            }
            console.log(this.orderList)
          }
        }).catch(e => {
          console.log(e)
        })
      },
      payOrder: function(index) {
        if (this.$cookies.get('user')===null || this.$cookies.get('user') === ''){
          this.$router.push({path: '/login'})
          return false
        }
        this.$axios({
          method: 'post',
          url: 'http://localhost:8080/api/order/orderpay',
          data: {
            orderId: this.orderList[index].orderId,
            userId: this.$cookies.get('user').userId,
            paymentUser: "asdf",
            paymentAccount: "asdfa",
            paymentMethod: "Alipay"
          },
          headers:{
            'Content-Type': 'application/json'
          }
        }).then(res => {
          console.log(res)
          let data = res.data
          if (data.resultCode === '0') {
            console.log(data)
          }
        })
      },
      takeDelivery: function (index) {
        if (this.$cookies.get('user')===null || this.$cookies.get('user') === ''){
          this.$router.push({path: '/login'})
          return false
        }
        this.$axios({
          method: 'post',
          url: 'http://localhost:8080/api/order/takedelivery',
          data: {
            orderId: this.orderList[index].orderId,
            orderDetailId: this.orderList[index].orderDetailId,
          },
          headers:{
            'Content-Type': 'application/json'
          }
        }).then(res => {
          console.log(res)
        }).catch(e => {
          console.log(e)
        })
      },
      afterSell: function (index) {
        if (this.$cookies.get('user')===null || this.$cookies.get('user') === ''){
          this.$router.push({path: '/login'})
          return false
        }
        this.$axios({
          method: 'post',
          url: 'http://localhost:8080/api/order/refundapply',
          data: {
            orderId: this.orderList[index].orderId,
            orderDetailId: this.orderList[index].orderDetailId,
            userId: this.$cookies.get('user').userId
          },
          headers:{
            'Content-Type': 'application/json'
          }
        }).then(res => {
          console.log(res)
        }).catch(e => {
          console.log(e)
        })
      },
      stateDes: function (index) {
        switch (index) {
          case '0':
            return '待支付'
          case '1':
            return '待发货'
          case '2':
            return '支付失败'
          case '3':
            return '待发货'
          case '4':
            return '待收货'
          case '5':
            return '已收货'
          case '6':
            return '待审核'
          case '7':
            return '待退费'
          case '8':
            return '适合不通过'
          case '9':
            return '待退费'
          case '10':
            return '已退费'
          default :
            return '未知'
        }
      }
    }
  }
</script>

<style scoped>
  *{
    padding: 0;
    margin: 0;
  }
  img {
    vertical-align: middle;
  }
  .hh{
    padding:0; list-style:none;
    margin:10px 10px;
  }
  .bb{
    width:80px; height:50px;
    display:inline-block;
    border-radius:8px; border:0px #000 solid;
    text-align:center; line-height:50px;
    cursor:pointer;
    transition:all 0.3s linear;
    margin-left:5px;
  }
  .bb:hover{
    background-color:#e6d6c6; color:#fff;
    border:0px #fff solid;
  }
  .bb.checked{
    background-color:#e6d6c6; color:#fff;
    border:0px #fff solid;
  }
  .outer9{
    width: 100%;
    height: 100%;
    background-color: #F2F2F2;
  }
  .outer9 .inter1{
    margin: 0 auto;
    width: 1120px;
    height: 94px;

  }
  .outer9 .inter1 h1{
    font-weight: normal;
    padding-top: 40px;
    margin-top: 60px;
  }
  .outer9 .inter2{
    width: 1120px;
    height: 492px;
    /*background-color: #795da3;*/
    margin: 0 auto;
    margin-bottom: 10px;
  }
  .outer9 .inter2 .inter21{
    width: 1118px;
    height: 54px;
    line-height:54px;
    background-color: #ffffff;
    font-size: 12px;
    color: #666666;
    border: 0.5px solid #cccccc;
    margin-bottom: 10px;
  }
  .outer9 .inter2 .checkAll{
    margin-left: 25px;
    width: 16px;
    height: 16px;
  }
  .outer9 .inter2 .check{
    margin-left: 25px;
    width: 16px;
    height: 16px;
  }
  .outer9 .s1{
    margin-left: 10px;
  }
  .outer9 .inter2 .inter21 .s2{
    margin-left: 40px;
  }
  .outer9 .inter2 .inter21 .s3{
    margin-left: 500px;
  }
  .outer9 .inter2 .inter21 .count{
    margin-left: 75px;
  }
  .outer9 .inter2 .inter21 .total{
    margin-left: 95px;
  }
  .outer9 .inter2 .money1{
    margin-left: 90px;
  }
  .outer9 .inter2 .inter21 .del{
    margin-left: 90px;
  }
  .outer9 .inter2 .inter22{
    width: 1118px;
    height: 326px;
    line-height: 100px;
    font-size: 12px;
    color: #666666;
    /*display: none;*/
  }
  .outer9 .inter2 .inter22 img{
    width: 66px;
    height: 66px;
    margin-left: 10px;
  }
  .outer9 .inter2 .inter22 ul li{
    width: 1118px;
    height: 101px;
    margin-bottom: 10px;
    background-color: #ffffff;
    list-style: none;
    border: 0.5px solid #cccccc;
  }
  .outer9 .inter2 .inter22 .money{
    margin-left: 40px;
  }
  .outer9 .inter2 .inter22 .sub{
    margin-left: 70px;
  }
  .outer9 .inter2 .inter22 .add{
    margin-left: 5px;
  }
  .outer9 .inter2 .del{
    margin-left: 80px;
  }
  .outer9 .inter3{
    width: 1118px;
    height: 90px;
    margin: 0 auto 50px;
    background-color: #ffffff;
    border: 0.5px solid #cccccc;
    font-size: 12px;
    color: #666666;
    /*display: none;*/
  }
  .outer9 .inter3 .inter31{
    width: 1058px;
    height: 48px;
    line-height: 48px;
    margin: 20px auto;
  }
  .outer9 .inter3 .ss1{
    margin-left: 40px;
  }
  .outer9 .inter3 .ss2{
    margin-left: 40px;
  }
  .outer9 .inter3 .foot{
    display: inline-block;
    float: right;
    width: 280px;
    height: 59px;
    line-height: 20px;
    /*background-color:red;*/
  }
  .outer9 .inter3 .foot .totalCount{
    color: #f44;
    font-size: 18px;
    font-weight: 700;
    padding: 0 4px;
    line-height: 20px;
  }
  .outer9 .inter3 .foot .totalPrice{
    font-size: 24px;
    font-weight: 700;
    margin-right: 6px;
    color: #f44;
    line-height: 18px;
  }
  .outer9 .inter3 .foot .ss3{
    float: right;
    padding: 0 60px;
  }
  .outer9 .inter3 .foot .ss4{
    color: #666;
    font-size: 16px;

  }
  .outer9 .inter3 .last{
    float: right;
    background-color: #FF5151;
    width: 194px;
    height: 48px;
    line-height: 48px;
    text-align: center;
  }
  .outer9 .inter3 .last a{
    text-decoration: none;
    margin: 0 auto;
    font-size: 18px;
    color: #ffffff;
  }
  .outer9 .inter3 .checkAll{
    width: 16px;
    height: 16px;
  }

  .outer9 .inter23{
    width: 1118px;
    height: 524px;
    border: 0.5px solid #cccccc;
    text-align: center;
    display: none;
  }
  .outer9 .inter23 .picture{
    width: 1118px;
    height: 250px;
    /*background-color: yellow;*/
    text-align: center;
  }
  .outer9 .inter23 .picture img{
    width: 150px;
    height: 120px;
    margin: 110px;
  }
  .outer9 .inter23 p{
    color: #999;
    padding-bottom: 20px;
    font-size: 16px;
  }
  .outer9 .inter23 a{
    background: #c78a49;
    padding: 0 20px;
    height: 26px;
    line-height: 24px;
    margin: 0 auto;
  }
  .outer9 .inter23 span{
    font-size: 12px;
    color: #ffffff;text-align: center;
  }

</style>
